<?php
include('rootlogin.php');
//include('../incsession.php');
session_start();
$level=2;
if($_POST['submit']=="next"){
	$i=1;
	$number=$_POST['MC'];
	while($i <= $number)
	{			
		if($_POST['Q'.$i]!='' && $_POST['A'.$i]!='' && $_POST['B'.$i]!='' && $_POST['C'.$i]!='' && $_POST['answer'.$i]!='' &&
			$_POST['Q'.$i]!=' ' && $_POST['A'.$i]!=' ' && $_POST['B'.$i]!=' ' && $_POST['C'.$i]!=' ' && $_POST['answer'.$i]!=' '){
			
			
			$Q = str_replace("'", "&#39;", $_POST['Q'.$i]);
			$Q = str_replace('"', '&quot;', $Q);
			$A = str_replace("'", "&#39;", $_POST['A'.$i]);
			$A = str_replace('"', '&quot;', $A);
			$B = str_replace("'", "&#39;", $_POST['B'.$i]);
			$B = str_replace('"', '&quot;', $B);
			$C = str_replace("'", "&#39;", $_POST['C'.$i]);
			$C = str_replace('"', '&quot;', $C);
			$choice=$_POST['answer'.$i];
			$ans=$_POST[$choice.$i];
			$ans = str_replace("'", "&#39;", $ans);
			$ans = str_replace('"', '&quot;', $ans);
			$query = "INSERT INTO multiple_choice (question, a, b, c, answer, topicid, level) 
					VALUES ('".$Q."',
							'".$A."', 
							'".$B."',
							'".$C."',
							'".$ans."',
							".$_SESSION['topicid'].", ".$level.")";
			$result = mysql_query($query,$user_con);
		}
		$i++;
	}
	header("location: open_question2.php");	
}
if(!isset($_POST['MC'])){
			$MC=1;
}
else {
			$MC=$_POST['MC'];
			$MC++;
}

?>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="framestyle.css" type="text/css" media="screen">
<style type="text/css">

</style>
</head>

<body>
<div id="wrapper">
<div id="title">Online Listening Comprehension Program</div>

<div id="main">
<hr/>
<div id="title2">FOR INTERMEDIATE LEVEL: MULTIPLE CHOICE</div>
<hr/>
<br><br>

<form method = POST action="multiple_choice2.php" >
<?php
$i=1;
while($i<=$MC){
	$Q = str_replace("'", "&#39;", $_POST['Q'.$i]);
	$Q = str_replace('"', '&quot;', $Q);
	$A = str_replace("'", "&#39;", $_POST['A'.$i]);
	$A = str_replace('"', '&quot;', $A);
	$B = str_replace("'", "&#39;", $_POST['B'.$i]);
	$B = str_replace('"', '&quot;', $B);
	$C = str_replace("'", "&#39;", $_POST['C'.$i]);
	$C = str_replace('"', '&quot;', $C);
	echo '<table>';
	echo '<tr><td align="right">Q'.$i.': <td><input class="area long" type="text" name="Q'.$i.'" value="'.$_POST['Q'.$i].'">
			<tr><td align="right">A: <td><input class="area long" type="text" name="A'.$i.'" value="'.$_POST['A'.$i].'">
			<tr><td align="right">B: <td><input class="area long" type="text" name="B'.$i.'" value="'.$_POST['B'.$i].'">
			<tr><td align="right">C: <td><input class="area long" type="text" name="C'.$i.'" value="'.$_POST['C'.$i].'">
			<tr><td align="right"><td>answer: <select name="answer'.$i.'">
			<option value='.$_POST['answer'.$i].'>'.$_POST['answer'.$i].'</option>
			<option value="A"';
	if(!isset($_POST['answer'.$i]))
		echo " selected";
	echo '>A</option>
			<option value="B">B</option>
			<option value="C">C</option>
			</select></table>';	
	echo "<br>";
	$i++;
	
}

echo "<input type='hidden' name='MC' value=".$MC.">";

?>
<div class="btn_right"><input type="submit" name = "submit" value = "add"></div><br>

<div class="btn_right"><input type="submit" name = "submit" value = "next"></div>
</form>



</div>
</div>
</body>

